package jsu.ljy.lostandfind.common;

/**
 * 统一响应结果类
 * 
 * <p>用于封装API响应结果，包含状态码、消息和数据。</p>
 * 
 * @author 罗嘉毅
 * @version 1.0
 * @since 2024-03-21
 * @param <T> 数据类型
 */
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    private Result() {
    }

    private Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200, "success", data);
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }

    public static <T> Result<T> ok(T data) {
        return success(data);
    }

    public static <T> Result<T> fail(int code, String message) {
        return error(code, message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
} 